package com.sun.services;

import java.io.InputStream;
import java.util.HashMap;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class XmlParser{
	
	public static HashMap<String, String> parse(InputStream istream) throws Exception{
		HashMap<String, String> hashMap = new HashMap<String, String>();
		
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		DocumentBuilder builder = factory.newDocumentBuilder();
		Document document = builder.parse(istream);
		Element root = document.getDocumentElement();
		Element version = (Element)root.getElementsByTagName("version").item(0);
		Element name = (Element)root.getElementsByTagName("name").item(0);
		Element url = (Element)root.getElementsByTagName("url").item(0);
		
		hashMap.put("version", version.getFirstChild().getNodeValue());
		hashMap.put("name", name.getFirstChild().getNodeValue());
		hashMap.put("url", url.getFirstChild().getNodeValue());

		return hashMap;
	}
}
